import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { projectSimple } from '/@/api/backs/foundation/foundation';
import moment from 'moment';

export const columns: BasicColumn[] = [
  {
    title: '项目名称',
    dataIndex: 'projectName',
  },
  {
    title: '划拨金额',
    dataIndex: 'amount',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    sorter: true,
    customRender: ({ record }) => {
      const time = record.createTime;
      return time ? moment(time).format('YYYY-MM-DD') : '-';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'amount',
    label: '划拨金额',
    component: 'InputNumber',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    field: 'projectId',
    label: '项目名称',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: projectSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择项目',
    },
  },
  {
    field: 'createTime',
    label: '创建时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    componentProps: {
      valueFormat: 'X',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'amount',
    label: '划拨金额',
    component: 'InputNumber',
    required: true,
    colProps: { span: 8 },
  },
  {
    field: 'projectId',
    label: '项目信息',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      api: projectSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择项目',
    },
  },
];
